home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-05-23 | 2.0 KB | 92 lines |
- // JFSapplet
- // This applet exists only to connect to a JFS server, and then run a
- // JFScomponent in the applet window.
- import java.awt.*;
- import java.io.*;
- import JFScomponent;
- import BorderPanel;
-
- public class JFSapplet extends java.applet.Applet
- {
- LoginWindow lw;
- JFScomponent co;
- JFSclient con;
-
- public void start()
- {
- // Get, load and add the component
- String compstr = getParameter("component");
- if (compstr == null)
- die("No component parameter given");
- Class c = null;
- try c = Class.forName(compstr);
- catch(ClassNotFoundException e)
- die("Class not found!");
- try co = (JFScomponent)c.newInstance();
- catch(InstantiationException e)
- die("Could not instantiate class");
- catch(IllegalAccessException e)
- die("Illegal access to class");
- co.init(this);
- setLayout(new BorderLayout());
- BorderPanel main = new BorderPanel(new Color(220,220,200), Color.black);
- main.setLayout(new BorderLayout());
- main.add("Center",co);
- add("Center",main);
-
- // Get the user's name and password (from param or requestor)
- String n = getParameter("username");
- String p = getParameter("password");
- if (n != null && p != null)
- login(n,p);
- else
- lw = new LoginWindow(this);
- }
-
- // stop
- // Disconnect from the JFS server
- public void stop()
- {
- if (con != null) {
- con.close();
- con = null;
- }
- }
-
- // action
- // Handle user input (from the login window)
- public boolean action(Event evt, Object o)
- {
- if (evt.target == lw && evt.arg.equals("Ok"))
- login(lw.getname(), lw.getpass());
- return true;
- }
-
- // login
- // Connect to the server once a name and password have been
- // somehow acquired
- void login(String name, String pass)
- {
- try con = new JFSclient(getCodeBase().getHost());
- catch(IOException e) {
- new ErrorWindow("Failed to connect to server");
- return;
- }
- try con.auth(name, pass);
- catch(RequestException e) {
- new ErrorWindow("Login failed : "+e.getMessage());
- return;
- }
- co.connect(con);
- }
-
- // die
- // Print a message and quit
- void die(String m)
- {
- System.out.println(m);
- System.exit(1);
- }
- }
-
-